/*******************************************************************************
iphone.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2007-10-17

	Copyright (C) 2007 °° 
	All rights reserved.
	
*******************************************************************************/
#ifndef _IPHONE_H_
#define _IPHONE_H_

#ifndef _OS_
#define _OS_WINNT_		0x001
#define _OS_LINUX_		0x002
#define _OS_FREEBSD_	0x003
#define _OS_APPLE_		0x004

#define _OS_		_OS_FREEBSD_
#define _OS_IPHONE_	_OS_
#endif

//#include "typedef.h"

typedef char CHAR;
typedef CHAR* LPSTR;

#ifdef __cplusplus
extern "C" {
#endif
	
#ifndef BASETYPES
#define BASETYPES
	
#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif
	
#ifndef FALSE
#define FALSE               false
#endif
	
#ifndef TRUE
#define TRUE                true
#endif
	
#ifndef IN
#define IN
#endif
	
#ifndef OUT
#define OUT
#endif
	
#ifndef OPTIONAL
#define OPTIONAL
#endif
	
#ifndef CALLBACK
#define CALLBACK
#endif
	
#ifndef CONST
#define CONST               const
#endif
	
	typedef unsigned char       BYTE;
	typedef unsigned short      WORD;
	typedef unsigned long       DWORD;
	
	typedef BYTE*				LPBYTE;
	typedef WORD*				LPWORD;
	typedef DWORD*				LPDWORD;
	
	typedef void				VOID;
	typedef char				CHAR;
	
//	typedef bool				BOOL;
	
	typedef long				LONG;
	typedef short				SHORT;
	
	typedef float               FLOAT;
	typedef double				DOUBLE;
	
	typedef VOID*				PVOID;
	typedef CHAR*				PCHAR;
	typedef BOOL*				PBOOL;
	typedef LONG*				PLONG;
	
	typedef FLOAT*				PFLOAT;
	typedef DOUBLE*				PDOUBLE;
	
	typedef BYTE*				PBYTE;
	typedef WORD*				PWORD;
	typedef DWORD*				PDWORD;
	
	typedef VOID*				LPVOID;
	typedef const VOID*			LPCVOID;
	
	typedef CHAR*				LPSTR;
	typedef const CHAR*			LPCSTR;
	
	typedef unsigned int        UINT;
	typedef unsigned short		WCHAR;
	
	typedef WCHAR*				LPWSTR;
	typedef const WCHAR*		LPCWSTR;
	
#if (_OS_ != _OS_WINNT_)
#define __int64 long long
#endif
	
	typedef int					INT32;	// 32-bit integer
	typedef __int64				INT64;	// 64-bit integer
	
	
	typedef int (CALLBACK *FARPROC)();
	
#endif//BASETYPES
	
	typedef int                 SINT;
	
	typedef INT64				PTR64;	// 64-bit pointer
	typedef INT32				PTR32;	// 32-bit pointer
	
	typedef PTR64				LFPTR;	// long file pointer
	typedef PTR32				SFPTR;	// short file pointer
	typedef SFPTR				FPTR;	// file pointer
	
	typedef	INT64				LSIZE;	// large size
	typedef	INT32				SSIZE;	// small size
	typedef UINT				USIZE;	// unsigned size
	
	typedef LSIZE				LOFFSET; // large offset
	typedef SSIZE				SOFFSET; // small offset
	typedef USIZE				UOFFSET; // unsigned offset
	
#define HIOFFSET(x)			((DWORD)(x >> 32))
#define LOOFFSET(x)			((DWORD)(x))
	
	typedef const void*			CPVOID;
	
	typedef	SINT				SCOUNT;	// short count
	typedef LONG				LCOUNT; // long count
	
	typedef DWORD				LWORDID;// Long Word ID
	typedef WORD				SWORDID;// short Word ID
	
	typedef LWORDID				LWID;
	typedef SWORDID				SWID;
	
	typedef LWID				WID;
	typedef const WID*			LCPWID;
	
#define INVALID_WORDID		0
#define INVALID_WID			0
	
	typedef DWORD				LDOCID;
	typedef WORD				SDOCID;
	
	typedef LDOCID				LDID;
	typedef SDOCID				SDID;
	
	typedef LDID				DID;
	typedef const DID*			LCPDID;
	
#define INVALID_DOCID		0
#define INVALID_DID			0
	
	typedef DWORD				LSID;
	typedef WORD				SSID;
	
#define INVALID_SID			0
	
	typedef DWORD				LWEIGHT;
	typedef WORD				SWEIGHT;
	typedef SWEIGHT				WEIGHT;
	
#define INVALID_WEIGHT		0
#define MAX_LWEIGHT			((LWEIGHT)-1)
#define MAX_SWEIGHT			((SWEIGHT)-1)
	
#define OUT_WEIGHT			0x0FFFFFFF
#define MAX_WEIGHT			(-1)
	
	typedef FARPROC				LPFUNC;
	
	
	typedef LONG LPARAM;
	typedef unsigned long ULONG;
	typedef BYTE*	LPBYTE;
	
#ifdef __cplusplus
}
#endif

//

#ifdef _UNICODE

typedef unsigned short	TCHAR;
typedef TCHAR*			LPTSTR;
typedef const TCHAR*	LPCTSTR;

#define __T(x)      L ## x
#define _T(x)       __T(x)
#define _TEXT(x)    __T(x)

#include "tcsproc.h"


#else // _MBCS

typedef CHAR	TCHAR;
typedef LPSTR	LPTSTR;
typedef LPCSTR	LPCTSTR;

#define __T(x)      x
#define _T(x)       __T(x)
#define _TEXT(x)    __T(x)

/* String functions */

#define _tcschr     strchr
#define _tcscspn    strcspn
#define _tcsncat    strncat
#define _tcsncpy    strncpy
#define _tcspbrk    strpbrk
#define _tcsrchr    strrchr
#define _tcsspn     strspn
#define _tcsstr     strstr
#define _tcstok     strtok

#define _tcsnset    _strnset
#define _tcsrev     _strrev
#define _tcsset     _strset

#define _tcscmp     strcmp
#define _tcsicmp    stricmp
#define _tcsnccmp   strncmp
#define _tcsncmp    strncmp
#define _tcsncicmp  strnicmp
#define _tcsnicmp   strnicmp

#define _tcscoll    strcoll
#define _tcsicoll   _stricoll
#define _tcsnccoll  _strncoll
#define _tcsncoll   _strncoll
#define _tcsncicoll _strnicoll
#define _tcsnicoll  _strnicoll


#define _tcscat     strcat
#define _tcscpy     strcpy
#define _tcsdup     _strdup

#define _tcslen     strlen
#define _tcsxfrm    strxfrm

#define _tcsclen    strlen
#define _tcsnccat   strncat
#define _tcsnccpy   strncpy
#define _tcsncset   _strnset

#define _tcslwr		_strlwr
#define _tcsupr		_strupr

#define _itot       _itoa
#define _ltot       _ltoa
#define _ultot      _ultoa
#define _ttoi       atoi
#define _ttol       atol

#define _ttoi64     _atoi64
#define _i64tot     _i64toa
#define _ui64tot    _ui64toa

#define _tprintf    printf
#define _ftprintf   fprintf
#define _stprintf   sprintf
#define _sntprintf  _snprintf
#define _vtprintf   vprintf
#define _vftprintf  vfprintf
#define _vstprintf  vsprintf
#define _vsntprintf _vsnprintf
#define _tscanf     scanf
#define _ftscanf    fscanf
#define _stscanf    sscanf


#define stricmp		strcasecmp
#define strnicmp	strncasecmp


inline char* _strlwr(char* pstr)
{
	char* p = pstr;
	while(*p)
	{
		if(*p >= 'A' && *p <= 'Z')
			*p = 'a' + (*p - 'A');
		p++;
	}
	return pstr;
}

inline char* _strupr(char* pstr)
{
	char* p = pstr;
	while(*p)
	{
		if(*p >= 'a' && *p <= 'z')
			*p = 'A' + (*p - 'a');
		p++;
	}
	return pstr;
}

#endif //_MBCS

#ifndef CP_ACP
#define	CP_ACP		936
#endif

#ifndef CP_UTF8
#define CP_UTF8		65001
#endif

inline bool IsDBCSLeadByte(BYTE b)
{
	return (b & 0x80);
}

#define MAKEWORD(a, b)      ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
#define MAKELONG(a, b)      ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
#define LOWORD(l)           ((WORD)(l))
#define HIWORD(l)           ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
#define LOBYTE(w)           ((BYTE)(w))
#define HIBYTE(w)           ((BYTE)(((WORD)(w) >> 8) & 0xFF))

#define MAX_PATH	260

#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define min(a,b)    (((a) < (b)) ? (a) : (b))

#endif//_IPHONE_H_
